//导入二次封装axios
import request from "@/utils/request";
import type { AddSkuApiParams } from "./models/skuModel";

// 使用枚举定义接口地址,方便后续修改
enum Api {
  addSkuUrl = "/admin/product/saveSkuInfo",
  getSkuListUrl = "/admin/product/findBySpuId",
  getSkuListPageUrl = "/admin/product/list",
  delSkuListPageUrl = "/admin/product/deleteSku",
  onSaleUrl = "/admin/product/onSale",
  cancelSaleUrl = "/admin/product/cancelSale",
}

/**
 * 添加sku的接口函数
 * @param data
 * @returns null
 */
export const addSkuApi = (data: AddSkuApiParams) => {
  return request.post<any, null>(Api.addSkuUrl, data);
};

/**
 *查看sku列表的接口函数
 * @param id
 * @returns
 */
export const getSkuListApi = (id: number) => {
  return request.get<any, any>(Api.getSkuListUrl + `/${id}`);
};

/**
 * 获取sku列表的接口函数
 * @param page
 * @param limit
 * @returns
 */
export const getSkuListPageApi = (page: number, limit: number) => {
  return request.get<any, any>(Api.getSkuListPageUrl + `/${page}/${limit}`);
};

/**
 * 删除sku的接口
 * @param id
 * @returns null
 */
export const delSkuListPageApi = (id: number) => {
  return request.delete<any, null>(Api.delSkuListPageUrl + `/${id}`);
};

/**
 * 上架的接口函数
 * @param id
 * @returns
 */
export const onSaleApi = (id: number) => {
  return request.get<any, any>(Api.onSaleUrl + `/${id}`);
};

/**
 * 下架的接口函数
 * @param id 
 * @returns 
 */
export const cancelApi = (id: number) => {
  return request.get<any, any>(Api.cancelSaleUrl + `/${id}`);
};
